//
//  OrderInformationViewController.m
//  GLGW_Shoping
//
//  Created by yang on 2018/12/7.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "OrderInformationViewController.h"
#import "OrderInformationViewModel.h"
#import "ExpressInforViewController.h"
#import "ApplyInvoiceViewController.h"
#import "DownloadContractViewController.h"
#import "FillInTheOrderViewController.h"
#import "ShopCarViewController.h"
#import "OrderInfomationDetailModel.h"

@interface OrderInformationViewController ()<OrderInforDelegate>
@property(nonatomic, strong) OrderInformationViewModel *orderInformationViewModel;
@end

@implementation OrderInformationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    self.orderInformationViewModel = [[OrderInformationViewModel alloc] initWithViewToViewModel:self.groupedTableView theSuperView:self.view];
    self.orderInformationViewModel.orderID = self.orderID;
    self.orderInformationViewModel.delegate = self;
}

#pragma mark -- OrderInforDelegate
- (void)expressDidSelectRowAtIndexPath:(NSIndexPath *)indexPath model:(OrderInfomationDetailDataModel *)detailDataModel
{
    if (indexPath.section == 0 && indexPath.row == 1) {
        ExpressInforViewController *expressVc = [ExpressInforViewController new];
        expressVc.orderID = detailDataModel.info.orderId;
        [self.navigationController pushViewController:expressVc animated:YES];
    }
}

- (void)bottomButAction:(GLGWButton *)o_but model:(OrderInfomationDetailDataModel *)detailDataModel
{
    switch (o_but.tag) {
        case 340: { // 下载合同
            DownloadContractViewController *vc = [DownloadContractViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 341: {// 再次购买
            ShopCarViewController *vc = [ShopCarViewController new];
            // 这里带过去数据
            NSArray *arr = detailDataModel.info.orderGoods;
            NSMutableString *muStr = [NSMutableString string];
            for (int i = 0; i < arr.count; i ++) {
                OrderInfomationDetailDataInfoOrderGoodsModel *listObjectModel = arr[i];
                if (i == arr.count - 1) {
                    [muStr appendFormat:@"%@",listObjectModel.goodsId];
                } else {
                    [muStr appendFormat:@"%@,",listObjectModel.goodsId];
                }
            }
            vc.goodsIDStr = muStr;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 342: // 取消并撤回
            
            break;
        case 343: // 取消
            
            break;
        case 344: // 去支付
            [self fillInTheOrder:detailDataModel.info.orderId];
            break;
        case 345: // 确认收货
            
            break;
        case 346: { // 提货单
            DownloadContractViewController *vc = [DownloadContractViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 347: {// 申请发票
            ApplyInvoiceViewController *vc = [ApplyInvoiceViewController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }

//    if (o_but.tag == 400) { //再次购买
//        ApplyInvoiceViewController * invoiceVC = [ApplyInvoiceViewController new];
//        [self.navigationController pushViewController:invoiceVC animated:YES];
//    } else { // 下载合同
//        DownloadContractViewController *vc = [DownloadContractViewController new];
//        [self.navigationController pushViewController:vc animated:YES];
//    }
}

- (void)fillInTheOrder:(NSString *)orderID
{
    FillInTheOrderViewController * fillTheVC = [FillInTheOrderViewController new];
    fillTheVC.orderID = orderID;
    [self.navigationController pushViewController:fillTheVC animated:YES];
}

@end
